<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="WEB-INF/jsp/include/public.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>${applicationTitle}</title>
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
		<meta http-equiv="description" content="This is my page" />
		<link rel="stylesheet" type="text/css" href="${resourcesBasePath}/css/login.css"></link>
		<script type="text/javascript" src="${resourcesBasePath}/javascript/framework/jquery.js"></script>
		<script type="text/javascript" src="${resourcesBasePath}/javascript/framework/md5.js"></script>
		<script type="text/javascript">
			document.onkeydown = function(e) {
				var ieKey = (document.all) ? window.event : e;
				var eventCode = (document.all) ? ieKey.keyCode : ieKey.which;
				var srcElement = (document.all) ? ieKey.srcElement : ieKey.target;
				if ((eventCode == 8 && ((srcElement.type != "textarea" && srcElement.type != "text" && srcElement.type != "password") || srcElement.readOnly))) { // 禁用后退键
					return false;
				}
				return true;
			}
			$(function() {
				var inputs = $("input");
				var i = 0;
				for (var i = 0; i < inputs.length; i++) {
					var input = inputs[i];
					var type = input.type;
					if (type == "text" || type == "password") {
						initKeyDown($(input));
					}
				}
			});
			function initKeyDown(input) {
				input.keydown(function(e) {
					var ieKey = (document.all) ? window.event : e;
					var eventCode = (document.all) ? ieKey.keyCode : ieKey.which;
					if (eventCode == 13) {
						doLogin();
					}
				});
			}
			/**
			 * 用户登录
			 */
			function doLogin() {
				if (validateLogin()) {
					var username = $("#username").attr("value");
					var password = $("#password").attr("value");
					var validCode = $("#validCode").attr("value");
					var url = "services/system/passport";
					var params = {
						"loginName" : username,
						"loginPass" : hex_md5(password),
						"validCode" : validCode
					};
					$.get(url, params, function(data, status) {
						if (data.result) {
							var result = data.result;
							if (result.code && result.code == "success.login") {
								var message = result.message;
								alert(message);
								window.location.href = "index.jsp";
							} else {
								
							}
						}
					}, "json");
				}
			}
			
			/**
			 * 验证用户登录
			 */
			function validateLogin() {
				var username = $("#username");
				var password = $("#password");
				var validCode = $("#validCode");
				return validate(username, "用户名不能为空!")
					&& validate(username, "用户名长度不合法!", 4)
					&& validate(password, "用户密码不能为空!")
					&& validate(validCode, "验证码不能为空!")
					&& validate(validCode, "验证码长度不合法!", 4);
			}
			
			/**
			 * 验证
			 */
			function validate(input, message, minLength) {
				var value = input.attr("value");
				if (minLength) {
					if (value == null || $.trim(value).length < minLength) {
						alert(message);
						input.focus();
						return false;
					}
				}
				if (value == null || $.trim(value).length == 0) {
					alert(message);
					input.focus();
					return false;
				}
				return true;
			}
			
			/**
			 * 获取验证码
			 */
			function show(imgObj) {
				if (imgObj) {
					imgObj.src = "services/system/validCode?random=" + Math.random();
				}
			}
		</script>
	</head>

	<body style="background-repeat: no-repeat; background-color: #9CDCF9; background-position: 0px 0px;">
		<div id="temp"></div>
		<table width="681" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top: 120px">
			<tr>
				<td width="353" height="259" align="center" valign="bottom" background="${resourcesBasePath}/images/login/1.gif">
					<table width="90%" border="0" cellspacing="3" cellpadding="0">
						<tr>
							<td align="right" valign="bottom" style="color: #05B8E4">
								Power by
								<a href="#" target="_blank">落羽社区</a> Copyright 2010
							</td>
						</tr>
					</table>
				</td>
				<td width="195" background="${resourcesBasePath}/images/login/2.gif">
					<table width="190" height="106" border="0" align="center" cellpadding="2" cellspacing="0">
						<tr>
							<td height="50" colspan="2" align="left">
								&nbsp;
							</td>
						</tr>
						<tr>
							<td width="60" height="30" align="left">
								用&nbsp;户&nbsp;名
							</td>
							<td>
								<input name="username" type="text"
									style="background: url(${resourcesBasePath}/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 120px; background-color: #FFFFFF"
									id="username" size="16"></input>
							</td>
						</tr>
						<tr>
							<td height="30" align="left">
								用户密码
							</td>
							<td>
								<input name="password" type="password"
									style="background: url(${resourcesBasePath}/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 120px; background-color: #FFFFFF"
									id="password" size="16"></input>
							</td>
						</tr>
						<tr>
							<td height="30">
								验&nbsp;证&nbsp;码
							</td>
							<td>
								<input name="validCode" type="text" id="validCode" size="4"
									style="background: url(${resourcesBasePath}/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 60px; background-color: #FFFFFF"
									maxlength="4"></input>
								<img src="services/system/validCode" title="看不清?点击刷新" align="absmiddle" onclick="javascript:show(this)" width="55" height="20"></img>
							</td>
						</tr>
						<tr>
							<td height="40" colspan="2" align="center">
								<img src="${resourcesBasePath}/images/login/tip.gif" width="16" height="16"></img>
								请勿非法登陆！
							</td>
						<tr>
							<td colspan="2" align="center">
								<input type="submit" name="submit" onclick="javascript:doLogin();"
									style="background: url(${resourcesBasePath}/images/login/5.gif) no-repeat" value=" 登  陆 "></input>
								<input type="reset" name="submit" style="background: url(${resourcesBasePath}/images/login/5.gif) no-repeat" value=" 取  消 "></input>
							</td>
						<tr>
							<td height="5" colspan="2"></td>
					</table>
				</td>
				<td width="133" background="${resourcesBasePath}/images/login/3.gif">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td height="161" colspan="3" background="${resourcesBasePath}/images/login/4.gif"></td>
			</tr>
		</table>
	</body>
</html>
